package one.stand.service.impl;

import com.github.vioao.wechat.api.component.AccountApi;
import com.github.vioao.wechat.bean.response.BaseResponse;
import com.jmp.base.dto.WechatComponentTokenResponse;
import com.jmp.feign.WechatFeign;
import one.stand.model.ResultModel;
import one.stand.service.AccountService;
import one.stand.util.AssertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: QIK
 * @CreateDate: 2019/5/13 13:33
 */
@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    private WechatFeign wechatFeign;

    @Override
    public BaseResponse bind(String appId, String openAppId) {
        ResultModel<WechatComponentTokenResponse> componentTokenResponseResultModel = wechatFeign.componentToken();
        AssertUtil.isTrue(componentTokenResponseResultModel);
        String token = componentTokenResponseResultModel.getData().getToken();
        return AccountApi.bind(token, appId, openAppId);
    }

    @Override
    public BaseResponse add(String appId) {
        ResultModel<WechatComponentTokenResponse> componentTokenResponseResultModel = wechatFeign.componentToken();
        AssertUtil.isTrue(componentTokenResponseResultModel);
        String token = componentTokenResponseResultModel.getData().getToken();
        return AccountApi.create(token, appId);
    }
}
